package week13.week_13_server;

import java.io.ObjectOutputStream;
import java.net.Socket;
import java.util.HashMap;
import java.util.List;

public class ChatRoom {
    static String roomName;
    static List<String> userList;

    public static List<String> getUserList() {
        return userList;
    }

    public static String getRoomName() {
        return roomName;
    }

    public static void setRoomName(String roomName) {
        ChatRoom.roomName = roomName;
    }

    public static void add(String username){
        userList.add(username);
    }

    public static void sendAllUser(Message msg){
        HashMap onlineUser = ServerInfo.getOnlineUser();
        for (String username:userList){
            if (onlineUser.containsKey(username)){
                try {
                    Socket s = (Socket) onlineUser.get(username);
                    ObjectOutputStream oos = new ObjectOutputStream(s.getOutputStream());
                    oos.writeObject(msg);
                }catch (Exception e){
                    e.printStackTrace();
                }
            }
        }
    }
}
